package com.zzyl.nursing.controller.member;


import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.AlertData;
import com.zzyl.nursing.dto.DayDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.dto.member.FamilyMemberDto;
import com.zzyl.nursing.dto.member.HealthDto;
import com.zzyl.nursing.service.FamilyMemberService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zzyl.common.core.controller.BaseController;

import java.util.List;

/** 老人家属Controller
 * 
 * @author ruoyi
 * @date 2025-07-31
 */
@RestController
@Slf4j
@RequestMapping("/member/user")
@Api(tags = "老人家属相关接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private FamilyMemberService familyMemberService;
    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto userLoginRequestDto) {
        LoginVo loginVo = familyMemberService.login(userLoginRequestDto);
        return success(loginVo);
    }
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public R<List<DayDataVo>> queryDeviceDataListByDay(@RequestParam String functionId, @RequestParam Long startTime, @RequestParam Long endTime, @RequestParam String iotId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        List<DayDataVo> list = familyMemberService.queryDeviceDataListByDay(functionId, startTime, endTime, iotId);
        return R.ok(list);
    }
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult bind(@RequestBody FamilyMemberDto dto) {
        familyMemberService.bind(dto);
        return success();
    }
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public R<List<FamilyMemberVo>> selectMyMember() {
        List<FamilyMemberVo> list = familyMemberService.selectMyMember();
        return R.ok(list);
    }
    @GetMapping("/list-by-page")
    @ApiOperation("查看家人列表分页查询")
    public R<List<FamilyMemberElderPageVo>> listByPage() {
        startPage();
        List<FamilyMemberElderPageVo> list = familyMemberService.listByPage();
        return R.ok(list);
    }
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult QueryDevicePropertyStatus(@RequestBody HealthDto healthDto) {
        log.warn("{}", healthDto);
        List<PropertyStatusInfoVo> InfoVos = familyMemberService.QueryDevicePropertyStatus(healthDto);
        HealthVo healthVo = new HealthVo();
// 将 ArrayList 数据组装进 healthVo 中
        healthVo.setPropertyStatusInfo(InfoVos);
        ResponseData responseData = new ResponseData(healthVo);
        return success(responseData);
    }
    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按天统计查询指标数据")
    public R<List<DayDataVo>> queryDeviceDataListByWeek(@RequestParam String functionId, @RequestParam Long startTime, @RequestParam Long endTime, @RequestParam String iotId, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) {
        List<DayDataVo> list = familyMemberService.queryDeviceDataListByWeek(functionId, startTime, endTime, iotId);
        return R.ok(list);
    }
}
